import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import login from '../components/login.vue'
// import index from '../components/index.vue'
// import Welcome from '../components/Welcome.vue'
import admin_user from '../components/admin/admin_user.vue'
import admin_role from '../components/admin/admin_role.vue'
import admin_admin from '../components/admin/admin_admin.vue'
import admin_teacher from '../components/admin/admin_teacher.vue'
import admin_instructor from '../components/admin/admin_instructor.vue'
import tourists_index from '../components/tourists/tourists_index.vue'
import tourists_Introduction from '../components/tourists/tourists_Introduction.vue'
import teacher_user from '../components/teacher/teacher_user.vue'
import teacher_index from '../components/teacher/teacher_index.vue'
import teacher_Welcome from '../components/teacher/teacher_Welcome.vue'
import teacher_Introduction from '../components/teacher/teacher_Introduction.vue'
import instructor_index from '../components/instructor/instructor_index.vue'
import instructor_Welcome from '../components/instructor/instructor_Welcome.vue'
import instructor_Introduction from '../components/instructor/instructor_Introduction.vue'
import instructor_user from '../components/instructor/instructor_user.vue'
import student_index from '../components/student/student_index.vue'
import student_Welcome from '../components/student/student_Welcome.vue'
import student_Introduction from '../components/student/student_Introduction.vue'
import admin_index from '../components/admin/admin_index.vue'
import admin_Welcome from '../components/admin/admin_Welcome.vue'
import admin_Introduction from '../components/admin/admin_Introduction.vue'

Vue.use(VueRouter)


const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/about',
      name: 'About',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    },
    {
      path: '/login',
      component: login
    },
    {
      path: '/tourists_index',
      component: tourists_index,
      children: [{
        path: '/tourists_Introduction',
        component: tourists_Introduction

      }],
    },
    // 管理员
    {
      path: '/admin_index',
      component: admin_index,
      redirect: '/admin_Welcome',
      children: [{
        path: '/admin_Welcome',
        component: admin_Welcome
      },
      {
        path:'/admin_role',
        component:admin_role
      },
      {
        path:'/admin_instructor',
        component:admin_instructor
      },
      {
        path:'/admin_user',
        component:admin_user
      },
      {
        path:'/admin_teacher',
        component:admin_teacher
      },
      {
        path:'/admin_admin',
        component:admin_admin
      },
      {
        path:'/admin_Introduction',
        component:admin_Introduction
      }
    ],
    },
    // 辅导员
    {
      path: '/instructor_index',
      component: instructor_index,
      redirect: '/instructor_Welcome',
      children: [{
        path: '/instructor_Welcome',
        component: instructor_Welcome
      },
      {
        path: '/instructor_user',
        component: instructor_user
      },
      {
        path: '/instructor_Introduction',
        component: instructor_Introduction
      },
      ],
    },
    // 学生
    {
      path: '/student_index',
      component: student_index,
      redirect: '/student_Welcome',
      children: [{
        path: '/student_Welcome',
        component: student_Welcome
      },
      {
        path: '/student_Introduction',
        component: student_Introduction
      },
      ],
    },
    // 教师
    {
      path: '/teacher_index',
      component: teacher_index,
      redirect: '/teacher_Welcome',
      children: [{
        path: '/teacher_Welcome',
        component: teacher_Welcome
      },
      {
        path: '/teacher_user',
        component: teacher_user
      },
      {
        path: '/teacher_Introduction',
        component: teacher_Introduction
      },

      ],
    },
   

  ]

})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转


  // 获取token
  const tokenStr = window.sessionStorage.getItem('token')

  next()
})

export default router
